﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SaleManagement.Controllers;

namespace SaleManagement.modules
{
    public partial class usLoaiHang : BaseUC
    {
        public bool add = false;
        public string Idcategory;
        public int row;
        private CategoriesController category;
        public usLoaiHang()
            :base()
        {
           
            InitializeComponent();
            category = new CategoriesController();
        }
        public override void InitGridData()
        {
            this.DataGridView.AutoGenerateColumns = false;
            this.DataGridView.ColumnHeadersVisible = true;
            DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Beige;
            columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
            DataGridView.ColumnHeadersDefaultCellStyle = columnHeaderStyle;


            DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxColumn();
            idColumn.DataPropertyName = "id";
            idColumn.HeaderText = "Id";

            DataGridViewTextBoxColumn created_atColumn = new DataGridViewTextBoxColumn();
            created_atColumn.DataPropertyName = "created_at";
            created_atColumn.HeaderText = "CreateAt";

            DataGridViewTextBoxColumn updated_atColumn = new DataGridViewTextBoxColumn();
            updated_atColumn.DataPropertyName = "updated_at";
            updated_atColumn.HeaderText = "UpdateAt";


            DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();
            nameColumn.DataPropertyName = "name";
            nameColumn.HeaderText = "Name";

            DataGridViewTextBoxColumn descriptionColumn = new DataGridViewTextBoxColumn();
            descriptionColumn.DataPropertyName = "description";
            descriptionColumn.HeaderText = "Description";

            DataGridViewTextBoxColumn IndustryColumn = new DataGridViewTextBoxColumn();
            IndustryColumn.DataPropertyName = "industry_id";
            IndustryColumn.HeaderText = "Industry";

            DataGridView.Columns.Add(idColumn);
            DataGridView.Columns.Add(nameColumn);
            DataGridView.Columns.Add(created_atColumn);
            //DataGridView.Columns.Add(updated_atColumn);
            DataGridView.Columns.Add(descriptionColumn);
            DataGridView.Columns.Add(IndustryColumn);
        }


        public override void onLoad()
        {
            this.DataGridView.DataSource = category.getdata(2);
        }
        public override void OnAdd(object sender, EventArgs e)
        {
            add = true;
            frmAdd_Edit_LoaiHang fm = new frmAdd_Edit_LoaiHang(this);
            fm.Show();
        }
        public override void OnEdit(object sender, EventArgs e)
        {
            add = false;
            if (Idcategory != null)
            {
                frmAdd_Edit_LoaiHang fm = new frmAdd_Edit_LoaiHang(this);
                fm.Show();
            }
            else
            {
                MessageBox.Show("ban phai chon loai hang muon sua");
            }
        }
        public override void OnDelete(object sender, EventArgs e)
        {
            if (MessageBox.Show("ban co muon xoa khong", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                CategoriesController obj = new CategoriesController();
                if (obj.deletecategory(Idcategory))
                {
                    MessageBox.Show(obj.mess);

                    onLoad();
                }
            }
        }
        public override void OnGridDataCellClick(object sender, DataGridViewCellEventArgs e)
        {
            Idcategory = this.DataGridView.SelectedCells[0].Value.ToString();
            row = DataGridView.CurrentCell.RowIndex;
        }
    }
}
